package com.work.daily.stream;

import com.work.daily.stream.data.Person;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Stream 的映射(map/flatMap)
 *
 * @author Shengkang.Mo
 * @create 2020-11-26 16:15
 */
public class Stream_5_2 {
    public static void main(String[] args) {
        //将员工的薪资全部增加10000。
        List<Person> personList = Person.initData();

        //不改变原来员工集合的方式
        List<Person> personListNew = personList.stream().map(person -> {
            Person personNew = new Person(person.getName(), 0, 0, null, null);
            personNew.setSalary(person.getSalary() + 10000);
            return personNew;
        }).collect(Collectors.toList());

        System.out.println("一次改动前:" + personList.get(0).getName() + "-->" + personList.get(0).getSalary());
        System.out.println("一次改动后:" + personListNew.get(0).getName() + "-->" + personListNew.get(0).getSalary());

        //改变原来员工集合的方式
        List<Person> personListNew2 = personList.stream().map(person -> {
            person.setSalary(person.getSalary() + 10000);
            return person;
        }).collect(Collectors.toList());

        System.out.println("两次改动前:" + personList.get(0).getName() + "-->" + personList.get(0).getSalary());
        System.out.println("两次改动后:" + personListNew2.get(0).getName() + "-->" + personListNew2.get(0).getSalary());
    }
}
